package com.hshx.controller;

import com.hshx.pojo.Grant;
import com.hshx.service.GrantService;
import com.hshx.util.RedisUtil1;
import com.hshx.vo.SalaryVo;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

@CrossOrigin
@RequestMapping("/salaryService")
@RestController
public class GrantController {
    @Resource
    private GrantService grantService;
    @Resource
    private RedisUtil1 redisUtil1;

    @RequestMapping("/addGrantAll")
    public boolean addGrantAll(Grant grant){
        if (grantService.save(grant)){
            return true;
        }
        return false;
    }

    /**
     * 根据id删除
     * @param grant_id
     * @return
     */
    @RequestMapping("/deleteID")
    public boolean deleteID(Integer grant_id){
        if (grantService.removeById(grant_id)){
            return true;
        }
        return false;
    }

    /**
     * 根据id批量删除
     * @param grant_id_list
     * @return
     */
    @RequestMapping("/deleteIDList")
    public boolean deleteIDList(String grant_id_list){
        if (grantService.removeByIds(Arrays.asList(grant_id_list.split(",")))){
            return true;
        }
        return false;
    }

    /**
     *根据条件分页查询薪酬发放记录
     * @param page
     * @param limit
     * @return
     */
    @RequestMapping("/getSalaryVoName")
    HashMap<String,Object> getSalaryVo1(int page, int limit,String name){
        if (grantService.getSalaryVo1(page, limit, name)==null){
            HashMap<String,Object> salaryVoMap=new HashMap<>();
            salaryVoMap.put("code",0);
            List<SalaryVo> salaryVoList1 = new ArrayList<>();
            salaryVoMap.put("data", salaryVoList1);
            salaryVoMap.put("count", 0);
            return salaryVoMap;
        }else{
            return grantService.getSalaryVo1(page, limit, name);
        }
    }

    /**
     * 分页查询薪酬发放记录
     * @param page
     * @param limit
     * @return
     */
    @RequestMapping("/getSalaryVo")
    public HashMap<String,Object> getSalaryVo(int page,int limit){
        return grantService.getSalaryVo(page, limit);
//        return null;
    }
}
